package com.ee.chat.admin.service.impl;

import com.ee.chat.admin.service.IHomeService;
import com.ee.chat.admin.service.IOperationService;
import com.ee.chat.common.bean.Result;
import com.ee.chat.common.dao.SysOrderMapper;
import com.ee.chat.common.dao.UserInviteLogMapper;
import com.ee.chat.common.dao.UserMapper;
import com.ndhutu.ee.util.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author AppiJ
 * @Date 2020/5/13 16:11
 */
@Service
public class HomeServiceImpl implements IHomeService {

    @Resource
    UserInviteLogMapper userInviteLogMapper;
    @Resource
    IOperationService operationService;
    @Resource
    SysOrderMapper sysOrderMapper;
    @Resource
    UserMapper userMapper;

    @Override
    public Result registerStatics(HttpServletRequest request, Integer type) throws Exception {
        Map<String, Object> data = new HashMap<>();

        String format;     //日期格式
        String startTime;  //开始时间
        if(type == 1){
            format = "%Y-%m-%d";
            startTime = DateUtil.getDayDate();
        }else{
            format = "%Y-%m";
            startTime = DateUtil.getYearDate();
        }

        List<Map<String, Object>> registerStaticsList = userInviteLogMapper.queryRegisterStatics(format, startTime);
        data.put("registerStaticsList", registerStaticsList);

        Integer registerUserTotal = userMapper.getRegisterUserTotal();
        data.put("registerUserTotal", registerUserTotal);

        operationService.addOperationLog(request, "获取各渠道注册用户统计数据");

        return Result.returnSuccess(data);
    }

    @Override
    public Result rechargeWithdrawStatics(HttpServletRequest request, Integer type) throws Exception {
        Map<String, Object> data = new HashMap<>();

        String format;     //日期格式
        String startTime;  //开始时间
        if(type == 1){
            format = "%Y-%m-%d";
            startTime = DateUtil.getDayDate();
        }else{
            format = "%Y-%m";
            startTime = DateUtil.getYearDate();
        }

        List<Map<String, Object>> rechargeWithdrawStaticsList = sysOrderMapper.queryTransactionStatics(format, startTime);
        data.put("rechargeWithdrawStaticsList", rechargeWithdrawStaticsList);

        Map<String, Object> rechargeAndWithdrawTotal = sysOrderMapper.getRechargeAndWithdrawTotal();
        data.put("rechargeAndWithdrawTotal", rechargeAndWithdrawTotal);

        operationService.addOperationLog(request, "获取用户充值提现统计数据");

        return Result.returnSuccess(data);
    }
}
